package spotor.client.ui;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import spotor.client.R;
import spotor.client.R.id;
import spotor.client.R.layout;
import spotor.client.R.string;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends Activity {
	/** Called when the activity is first created. */
	private static String email,password;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);		
	}
	
	public void onLoginClick(View v)
	{
		email = ((EditText)(findViewById(R.id.mail_editText))).getText().toString();
		password = ((EditText)(findViewById(R.id.password_editText))).getText().toString();
		if(checklogininfo(email,password))
		{
			login(email,password);
			Intent intent = new Intent();
			intent.setClass(LoginActivity.this,HomeActivity.class);				
			startActivity(intent);
		}
		else
		{
			Toast.makeText(getApplicationContext(),getString(R.string.login_pop),Toast.LENGTH_SHORT).show();
		}
	}
	
	public void onSignupClick(View v)
	{
		// TODO Auto-generated method stub
		Intent intent = new Intent();
		intent.setClass(LoginActivity.this,SignupActivity.class);
		startActivity(intent);
	}
	//validation Method
	private Boolean checklogininfo(String email,String password)
	{
		Pattern pattern = Pattern.compile(".+@.+\\.[a-z]+");
		Matcher matcher = pattern.matcher(email);
		return matcher.matches();
	}
	
	
	//Login Method
	protected void login(String email, String password) {
		// TODO Auto-generated method stub
		Log.i("Login-info","Your Email is:"+email+".Your Password is:"+password);
	}
}